﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using FamilyTree.localhost8081;
using Microsoft.Win32;
using System.Net;
using System.Net.Sockets;

namespace FamilyTree
{
    public partial class FrmLogin : Form
    {
        public FrmLogin()
        {
            InitializeComponent();
        }

        private void FrmLogin_Load(object sender, EventArgs e)
        {

        }
        //登录按钮
        private void btnLogin_Click(object sender, EventArgs e)
        {
            Login();
        }
        //取消按钮
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void lnlRes_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            FrmRes frm = new FrmRes();
            frm.ShowDialog();
        }
        private void Login() {
            string id = textBox1.Text.Trim();
            string pwd = textBox2.Text;
           string ip_addr =string.Empty;
            string HostName = Dns.GetHostName(); //得到主机名
            IPHostEntry IpEnter = Dns.GetHostEntry(HostName);
            for (int i = 0; i < IpEnter.AddressList.Length; i++)
            {
                if (IpEnter.AddressList[i].AddressFamily == AddressFamily.InterNetwork)
                {
                    ip_addr = IpEnter.AddressList[i].ToString();
                }
            }

            localhost8081.WebServiceTestSoapClient us = new WebServiceTestSoapClient();
            string message = us.Login(id, pwd,ip_addr);
            if (string.IsNullOrEmpty(message))
            {
                caidanlan.id = id;
                MessageBox.Show("登录成功", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                this.DialogResult = System.Windows.Forms.DialogResult.OK;
            }
            else
            {
                MessageBox.Show(message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void label1_Click(object sender, EventArgs e)
        {
            Login();
        }

        private void label2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
